﻿using FMusicReload.NetMusicNetwork;
using FMusicReload.Utils;
using HandyControl.Controls;
using HTBInject.Utils;
using System;
using System.Windows;

namespace FMusicReload.Views
{
    public partial class SearchView 
    {
        public static string PassValue { set; get; }

        private LogHelper lh = new LogHelper("SearchView");


        public delegate void Switcher(object obj);
        public static event Switcher PlayMusic;

        public SearchView()
        {
            InitializeComponent();
            if (!(PassValue is null))
            {
                Search.Text = PassValue;
                var music_serach = new MusicSearch(Search.Text);
                results.ItemsSource = music_serach.GetModel();
                GC.Collect();
            }
            PassValue = null;
            lh.SendLog("SearchView Load Done!", LogHelper.LogType.Info);
            GC.Collect();

            background1.Background = StaticColorAssets.GetBasicColor();
            background1.BorderBrush = StaticColorAssets.GetBorderColor();

            play.Click += (s, e) =>
            {
                if (!(results.SelectedIndex is -1))
                    PlayMusic(results.SelectedItem);
                else
                    Growl.WarningGlobal("您没有选中您要播放的音乐");
            };
        }

        private void Search_SearchStarted(object sender, HandyControl.Data.FunctionEventArgs<string> e)
        {
            var music_serach = new MusicSearch(Search.Text);
            results.ItemsSource = music_serach.GetModel();
            GC.Collect();
        }

        private void results_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {

        }
    }
}
